CLS
OPEN "rope.in" FOR INPUT AS #1
OPEN "rope.out" FOR OUTPUT AS #2

INPUT #1, n
DIM a(n), b(n)

FOR i = 1 TO n
  INPUT #1, a(i), b(i)
NEXT i

FOR i = 1 TO n - 1
  FOR j = i TO n
    IF a(i) > a(j) THEN
      t = a(i): a(i) = a(j): a(j) = t
      t = b(i): b(i) = b(j): b(j) = t
    END IF
  NEXT j
NEXT i

cnt = 0
FOR i = 1 TO n - 1
  FOR j = i TO n
    IF b(i) > b(j) THEN cnt = cnt + 1
  NEXT j
NEXT i

PRINT #2, LTRIM$(STR$(cnt))

CLOSE #1, #2
END

